package com.wimcorp.magic.dataloader.abilities;

import java.util.Map;
import java.util.Set;

import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.user.client.ui.ListBox;
import com.wimcorp.magic.data.AbilityData;
import com.wimcorp.magic.input.AbilityInput;

public class AddCardCountCounterWidget extends AbilityWidget {

	private ListBox locationList;
	private ListBox targetList;
	private ListBox typeList;

	public AddCardCountCounterWidget(AbilityInput ability) {
		super(ability);
	}

	protected void initAbilityFields() {
		super.initAbilityFields();
		locationList = new ListBox();
		targetList = new ListBox();
		typeList = new ListBox();

		addInputSingleLocationList("Location", locationList, 0);
		addInputSingleTargetList("Target", targetList, 1);
		addInputSingleTypeList("Type", typeList, 2);

	}

	public JSONObject getAbilityConfig() {
		JSONObject config = super.getAbilityConfig();
		config.put("location", getSelectedItems(locationList));
		config.put("target", getSelectedItems(targetList));
		config.put("type", getSelectedItems(typeList));
		return config;
	}

	public void load(AbilityData abilityData) {
		super.load(abilityData);
		JSONObject config = (JSONObject) JSONParser.parseLenient(abilityData.getConfig());
		
		loadListBox(locationList, config.get("counterLocation"));
		loadListBox(targetList, config.get("counterTarget"));
		loadListBox(typeList, config.get("counterType"));

	}

}
